package parse_and_index.model;

import java.util.ArrayList;


public class Token implements java.io.Serializable {

	  private static final long	 serialVersionUID = -8022277986304803406L;
	  private String				tokenValue;
	  private final ArrayList<Page> pages;
	  private long				  documentID;
	  private TermFrequency		 termFrequency;						   // document tf

	  public Token(final String val, final long id) {
			tokenValue = val;
			setDocumentID(id);
			pages = new ArrayList<Page>();
			termFrequency = new TermFrequency();
	  }

	  public void addPage(final int pageNumber) {
			for (final Page page : pages) {
				  if (page.getPageNumber() == pageNumber) {
						page.incrementHitCount();
						return;
				  }
			}
			pages.add(new Page(pageNumber));
	  }

	  public String getTokenValue() {
			return tokenValue;
	  }

	  public void setTokenValue(final String tokenValue) {
			this.tokenValue = tokenValue;
	  }

	  public long getDocumentID() {
			return documentID;
	  }

	  void setDocumentID(final long documentID) {
			this.documentID = documentID;
	  }

	  public TermFrequency getTermFrequency() {
			return termFrequency;
	  }

	  public void setTermFrequency(final TermFrequency termFrequency) {
			this.termFrequency = termFrequency;
	  }

	  public ArrayList<Page> getPages() {
			return pages;
	  }

	  @Override
	  public String toString() {
			String ret = getDocumentID() + "; ";
			ret += pages.get(0).getPageNumber();
			for (int i = 1; i < pages.size(); i++) {
				  ret += ", " + pages.get(i).getPageNumber();
			}
			return ret + " ; tf  " + termFrequency + ", " + tokenValue + ".";
	  }
}